package com.itheima.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;


@Component
public class LogTimeAspect implements Ordered {
    @Override
    public int getOrder() {
        return Integer.MIN_VALUE;
    }


    public Object around(ProceedingJoinPoint joinPoint){

        //返回值
        Object result=null;

        try {
            System.out.println("我是~~~~~~~~~~~LogTimeAspect");
            //System.out.println("之前");
            long start = System.currentTimeMillis();

            //业务代码...

            //调用这个方法时候  底层就会取出 方法对象参数对象 目标对象 method.invoke(目标,参数)
            result=joinPoint.proceed();



            //afterReturning
            //System.out.println("正确之后");
            long end = System.currentTimeMillis();

            System.out.println(joinPoint.getTarget().getClass().getName()+"的"+joinPoint.getSignature().getName()+"花费了:"+(end-start)+"毫秒");
        }catch (Throwable e){
            //afterThrowing
            System.out.println("异常之后");
        }finally {
            //after
            //System.out.println("最终!!!");

        }

        return result;


    }





}
